﻿<?php
require_once 'include/base.php';
require_once 'include/topwrap.php';
require_once 'include/pagination.php';
require_once 'include/staticdata.php';
require_once 'include/global.func.php';
$smarty = new TopSmartyBase();


$top_config = Taoapi_Config::Init();
$top_config->setTestMode(false)->setAppKey('12014026')->setAppSecret('4fef4d085134f4070cc84f3bb0b2d4fd');
//$top_config->setTestMode(false)->setAppKey('test')->setAppSecret('test');
$top_config->setCharset('UTF-8');
$taoapi = new TopWrap(false,true);
$cat_items = $taoapi->getItemCats();

$tmpcats   = $cat_items['item_cats']['item_cat'];
$count     = count($tmpcats);
for( $i=0; $i<$count; $i++ )
{
	$tmpcats[$i]['cat_url'] = url('list',array('catid'=>$tmpcats[$i]['cid']));
}
$smarty->getSmarty()->assign('item_cats',$tmpcats);
unset($tmpcats);
unset($cat_items);

$cat_items = $taoapi->getItemCats($_GET['catid']);
$tmpcats   = $cat_items['item_cats']['item_cat'];
$count     = count($tmpcats);
for( $i=0; $i<$count; $i++ )
{
	$tmpcats[$i]['cat_url'] = url('list',array('catid'=>$tmpcats[$i]['cid']));
}
$smarty->getSmarty()->assign('sub_item_cats',$tmpcats);
$smarty->getSmarty()->assign('empty_sub_cats',empty($cat_items['item_cats']['item_cat']));

$sorts = StaticData::getSort();
$sort  = intval($_GET['sort']);
$strSort = 'credit_desc';
if($sort <= 5)$strSort = $sorts[$sort][1];
$smarty->getSmarty()->assign('curnav', $sort);
$pageno=intval($_GET['page'])<=0 ? 1 : intval($_GET['page']);
//$items = $taoapi->getItems($_GET['catid'],$pageno,15,$strSort);
$items = $taoapi->searchItems($_GET['catid'],$q, $pageno, 15, $strSort);
$tmpitems = $items['taobaoke_items']['taobaoke_item'];
$count = count($tmpitems);
for($i = 0; $i < $count; $i++)
{
	$tmpitems[$i]['item_url'] = url('item',array('num_iid'=>$tmpitems[$i]['num_iid']));
}
$pagination = new Pagination($items['total_results']);
$smarty->getSmarty()->assign('catnav',gen_nav($_GET['catid'], &$taoapi));
$smarty->getSmarty()->assign('pagination', $pagination->getPagination());
$smarty->getSmarty()->assign('items',$tmpitems);
$smarty->getSmarty()->assign('get',$_GET);
$smarty->getSmarty()->display('search.tpl');
